package com.ouc.openplatform.zykt.authManage.service.impl;
import java.util.List;
import com.github.abel533.entity.Example;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ouc.openplatform.pojo.EUDataGridResult;
import com.ouc.openplatform.zykt.authManage.dao.NJ_UserInfoDAO;
import com.ouc.openplatform.zykt.authManage.model.NJ_UserInfo;
import com.ouc.openplatform.zykt.authManage.service.NJ_UserInfoService;
import com.ouc.openplatform.zykt.authManage.vo.NJ_UserInfoVo;

public class NJ_UserInfoServiceImpl implements NJ_UserInfoService{
	
	private NJ_UserInfoDAO nj_userInfoDao;
    
	public NJ_UserInfoDAO getNj_userInfoDao() {
		return nj_userInfoDao;
	}

	public void setNj_userInfoDao(NJ_UserInfoDAO nj_userInfoDao) {
		this.nj_userInfoDao = nj_userInfoDao;
	}

	
	@Override
	public int saveUserInfo(NJ_UserInfo userInfo){
		return nj_userInfoDao.insert(userInfo);
	}
	@Override
	public int deleteUserInfo(int id){
		return nj_userInfoDao.deleteByPrimaryKey(id);
	}
	
	@Override
	public int updateUserInfo(NJ_UserInfo userInfo){
		return nj_userInfoDao.updateByPrimaryKeySelective(userInfo);
	}
	
	//4.获取所有用户信息-----sxl
	@Override
	public List<NJ_UserInfo>getUserInfo(NJ_UserInfo userinfo){
		Example example = new Example(NJ_UserInfo.class);
		example.createCriteria().andLike("realname", userinfo.getRealname()==null?"":userinfo.getRealname());
		example.createCriteria().andLike("userno", userinfo.getUserno()==null?"":userinfo.getUserno());
		return nj_userInfoDao.selectByExample(example);
	}
	
	//5.查询所有用户(easyui专用)-----sxl
	@Override
	public EUDataGridResult getAllUserInfo(NJ_UserInfo userinfo, int page, int rows) {
		//分页处理
		PageHelper.startPage(page, rows);
		//List<NJ_UserInfo> select = nj_userInfoDao.select(userinfo);
		List<NJ_UserInfoVo> select=nj_userInfoDao.findAllUserInfo(userinfo);
		//创建一个返回值对象
		EUDataGridResult result = new EUDataGridResult();
		result.setRows(select);
		//取记录总条数
		//PageInfo<NJ_UserInfo> pageInfo = new PageInfo<NJ_UserInfo>(select);
		PageInfo<NJ_UserInfoVo> pageInfo = new PageInfo<NJ_UserInfoVo>(select);
		result.setTotal(pageInfo.getTotal());
		return result;
	}
	
	@Override
	public int getAllCount()
	{
		return nj_userInfoDao.selectCount(null);
		
	}
	
	@Override
	public int ifExistence(NJ_UserInfo user)
	{
		return nj_userInfoDao.select(null)==null?0:1;
		
	}
	
	//根据用户工号和姓名模糊查询用户信息
	@Override
	public int getCountBynoname(String userno, String username) {
		return nj_userInfoDao.getCountBynoname(userno, username);
	}

	
	
}
